<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商品管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all"/>
    <link rel="stylesheet" href="__CSS__/admin.css" media="all">
    <style type="text/css">

        /* tooltip */
        #tooltip {
            position: absolute;
            border: 1px solid #ccc;
            background: #333;
            padding: 2px;
            display: none;
            color: #fff;
        }
        .bc{
            background-color: #009688;
        }
    </style>
</head>
<body style="padding:10px;">
<div class="tplay-body-div">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">商品管理</li>
            <li><a href="{:url('admin/goods/edit_goods')}" class="a_menu">新增商品</a></li>
        </ul>
    </div>
    <form class="layui-form serch" action="{:url('admin/goods/goods')}" method="post">
        <div class="layui-form-item" style="float: left;">
            
            <div class="layui-input-inline">
                <input type="text" name="keywords" lay-verify="title" autocomplete="off" placeholder="请输入名称关键词查询"
                       class="layui-input layui-btn-sm" value="{$keywords}">
            </div>
            <button class="layui-btn layui-btn-danger layui-btn-sm bc" lay-submit="" lay-filter="serch">立即查询</button>
        </div>
    </form>
    <table class="layui-table" lay-size="sm">
        <colgroup>
            <col width="150">
            <col width="100">
            <col width="150">
            <col width="80">
            <col width="100">
            <col width="100">
            <col width="150">
            <col width="100">
            <col width="100">
            <col width="150">
        </colgroup>
        <thead>
        <tr>
            <th>商品名称</th>
            <th>缩略图</th>
            <th>商品分类</th>
            <th>商品单位</th>
            <th>商品价格</th>
            <th>已售销量</th>
            <th>添加时间</th>
            <th>是否推荐</th>
            <th>上架状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="info" id="vo"}
        <tr>
            <td>{$vo.title}</td>
            <td>
                {if condition="$vo['thumb'] neq ''"}
                <a href="{$vo.thumb}" class="tooltip"><img src="{$vo.thumb}" width="50" height="40"></a>
                {/if}
            </td>
            <td>{$vo.type_name}</td>
            <td>{$vo.unit}</td>
            <td>{$vo.price}</td>
            <td>{$vo.have_sales}</td>
            <td>{$vo.insert_at}</td>
            <td>
                <div class="layui-form-item layui-form">
                    <input type="checkbox" {if condition="$vo['is_recommend'] eq 1"}checked="checked"{/if} name="open" id="{$vo.id}" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
                </div>
            </td>
            <td>
                {if condition="$vo['is_shelves'] eq 1"}
                <button type="button" class="layui-btn layui-btn-sm off_shelves" id="{$vo.id}">下架</button>
                {else /}
                <button type="button" class="layui-btn layui-btn-sm on_shelves" id="{$vo.id}">上架</button>
                {/if}
            </td>
            <td class="operation-menu">
                <div class="layui-btn-group">
                    <a class="layui-btn layui-btn-sm" href="{:url('admin/goods/edit_goods',['id'=>$vo.id])}"><i class="layui-icon"></i></a>
                    <button type="button" class="layui-btn layui-btn-sm delete" id="{$vo.id}"><i class="layui-icon"></i></button>
                </div>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    {$page}
    {include file="public/foot"}
    <script>
        layui.use(['form', 'layedit', 'laydate'], function(){
            var form = layui.form,
                layer = layui.layer,
                layedit = layui.layedit,
                laydate = layui.laydate;

            //监听指定开关
            form.on('switch(switchTest)', function(data){
                var id = $(this).attr('id');
                var editswitch = '';
                this.checked?editswitch=1:editswitch=2;
                $.ajax({
                    url: "{:url('admin/goods/edit_goods_recommend')}",
                    data: {id:id,switch: editswitch},
                    success: function (res) {
                        setTimeout(function () {
                            location.reload();
                        }, 100)
                    }
                })
            });
        });
    </script>
    <script type="text/javascript">
        $('.delete').click(function () {
            var id = $(this).attr('id');
            layer.confirm('确定要删除吗?', function (index) {
                $.ajax({
                    url: "{:url('admin/goods/del_goods')}",
                    data: {id: id},
                    success: function (res) {
                        layer.msg(res.msg);
                        setTimeout(function () {
                            location.reload();
                        }, 1000)
                    }
                })
            })
        })
    </script>
    <script type="text/javascript">
        $('.off_shelves').click(function () {
            var id = $(this).attr('id');
            layer.confirm('确定要下架吗?', function (index) {
                $.ajax({
                    url: "{:url('admin/goods/edit_shelves')}",
                    data: {id: id,act:2},
                    success: function (res) {
                        layer.msg(res.msg);
                        setTimeout(function () {
                            location.reload();
                        }, 1000)
                    }
                })
            })
        })
    </script>
    <script type="text/javascript">
        $('.on_shelves').click(function () {
            var id = $(this).attr('id');
            layer.confirm('确定要上架吗?', function (index) {
                $.ajax({
                    url: "{:url('admin/goods/edit_shelves')}",
                    data: {id: id,act:1},
                    success: function (res) {
                        layer.msg(res.msg);
                        setTimeout(function () {
                            location.reload();
                        }, 1000)
                    }
                })
            })
        })
    </script>
</div>
</body>
</html>
